#!/usr/bin/env python

import sys
import signal
try:  # indigo
    from python_qt_binding.QtGui import QApplication, QMainWindow
except ImportError:  # kinetic+ (pyqt5)
    from python_qt_binding.QtWidgets import QApplication, QMainWindow

from rqt_py_trees.behaviour_tree import RosBehaviourTree

from rqt_gui.main import Main

# Crude, but needed to make sure that the display of all the GUI arguments works
# when the -h option is given. If we try to parse options before they won't be
# displayed.
if RosBehaviourTree.no_roscore_switch in sys.argv:
    app = QApplication(sys.argv)
    window = QMainWindow()
    myapp = RosBehaviourTree(window)
    window.show()
    signal.signal(signal.SIGINT, signal.SIG_DFL)
    sys.exit(app.exec_())
else:
    main = Main()
    sys.exit(main.main(sys.argv, standalone='rqt_py_trees.behaviour_tree.RosBehaviourTree', plugin_argument_provider=RosBehaviourTree.add_arguments))
